<template>
  <tjcom ref="tjcom" />
</template>
<script>
// 扫码统计
import bus from "@/store/bus";
import tool from "@/utils/tool";
import tjcom from "./tjcom.vue";
export default {
  name: 'smtjm',
  components: {tjcom},
  data () {
    return {
      offsetH: 300,
      list: [],
      cols1: [
        {type: 'seq', width: 40},
        {field: 'bills', title: '票号', width: 110,},
        {field: 'licence', title: '车辆', width: 120,align: 'center',},
        {field: 'state', title: '状态',align: 'center' },
      ],
      cols2: [
        {type: 'seq', width: 40},
        {field: 'invName', title: '商品名称', },
        {field: 'spec', title: '规格', width: 60,align: 'center',},
        {field: 'unit', title: '单位', width: 60,align: 'center',},
        {field: 'qty', title: '数量',align: 'right' ,width: 80},
        {field: 'assQty', title: '辅助数量',align: 'right' ,width: 130},
      ],
    }
  },
  computed: {
    gh () {
      return window.innerHeight - this.offsetH
    },
    psList () {
      let ret = []
      for (let i = 0; i < this.list.length; i++) {
        ret.push({
          bills: this.list[i].billNo,
          licence: this.list[i].licence,
          state: this.list[i].state,
        })
      }
      return ret
    },
    goods () {
      let ret = []
      let list = []
      this.list.map(row => {
        row.goods.map(r => {
          list.push(r)
        })
      })
      let gp = tool.xe.groupBy(list, 'invId')
      for(let i in gp) {
        let good = {
          invId: gp[i][0].invId,
          invName: gp[i][0].invName,
          spec: gp[i][0].spec,
          unit: gp[i][0].unit2?gp[i][0].unit2:gp[i][0].unit1,
          unit1: gp[i][0].unit1,
          unit2: gp[i][0].unit2,
          qty: tool.xe.sum(gp[i], 'qty'),
          assQty: ''
        }
        good.assQty = this.toAssQty(good)
        ret.push(good)
      }
      return ret
    }
  },
  deactivated () {
    bus.$off('scan-ret', this.scanPs)
  },
  activated () {
    bus.$on('scan-ret', this.scanPs)
  },
  methods: {
    scanPs ({code}) {
      this.$refs.tjcom.scanPs({code})
    },
  }
}
</script>